﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Lswweb.Model;
using Lswweb.Domain;
using FredCK.FCKeditorV2;
using System.Configuration;

namespace Lswweb.Controls
{
    public class CommentaryCreate : SkinnedEditControl<CommentaryInfo>
    {
        private TextBox tbxBody;
        private TextBox tbxLinkMan;
        private TextBox tbxFeedBack;

        protected override void InitSkin(Control skin)
        {
            tbxBody = (TextBox)skin.FindControl("tbxBody");
            tbxLinkMan = (TextBox)skin.FindControl("tbxLinkMan");
            tbxFeedBack = (TextBox)skin.FindControl("tbxFeedBack");
        }

        protected override void Add(CommentaryInfo model)
        {
            Products.AddCommentary(model);
        }

        protected override void Update(CommentaryInfo model)
        {
            Products.UpdateCommentary(model);
        }

        protected override CommentaryInfo FindById(int id)
        {
            return Products.GetCommentary(id);
        }

        protected override CommentaryInfo ModelByFrom
        {
            get
            {
                CommentaryInfo info = new CommentaryInfo();
                info.ProductId = ProductId;
                info.UserId = SiteContext.Current.User.Id;
                info.UserName = tbxLinkMan.GetValue<string>();
                info.Content = tbxBody.GetValue<string>();
                info.FeedBack = tbxFeedBack.GetValue<string>();

                return info;
            }
            set
            {
                tbxLinkMan.SetValue(value.UserName);
                tbxBody.SetValue(value.Content);
                tbxFeedBack.SetValue(value.FeedBack);
            }
        }

        private int productId = SiteContext.Current.CategoryId;
        public int ProductId
        {
            get { return this.productId; }
            set 
            { 
                this.productId = value;
                this.id = 0;
            }
        }

        private int id = SiteContext.Current.Id;
        protected override int Id
        {
            get
            {
                return id;
            }
        }

        protected override string DefaultSkinFilename
        {
            get { return "CommentaryAdd.ascx"; }
        }
    }
}
